﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using FANUC.DTO;

namespace FANUC.Controllers
{
    public class TodayAllRobotsOutputsController : ApiController
    {
        private FANUCDB db = new FANUCDB();

        [ResponseType(typeof(TodayAllRobotsOutputsDtoOutput))]
        public IHttpActionResult Get()
        {
            #region Test
            if (Helper.IsTest)
            {
                TodayAllRobotsOutputsDtoOutput testData = new TodayAllRobotsOutputsDtoOutput();
                testData.Date = System.DateTime.Now.Date;
                testData.OutputsQuantity = 10000;
                return Ok(testData);
            }
            #endregion
            DateTime today = System.DateTime.Now.Date;
            int count = db.Part_Unit.Where(a => a.Start_Time >= today).Count();
            count += db.Spot_Part_Unit.Where(a => a.Start_Time >= today).Count();
            count += db.Seal_Part_Unit.Where(a => a.Start_Time >= today).Count();
            count += db.Polish_Part_Unit.Where(a => a.Start_Time >= today).Count();
            count += db.Press_Part_Unit.Where(a => a.Start_Time >= today).Count();

            TodayAllRobotsOutputsDtoOutput data = new TodayAllRobotsOutputsDtoOutput();
            data.Date = today;
            data.OutputsQuantity = count;
            return Ok(data);
        }

        [ApiExplorerSettings(IgnoreApi = true)]
        public string Options()
        { return null; }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
